<?PHP 
if (!session_start()) { session_start(); };
/*if (!isset($_SESSION['lgnapproved'])) {
	die(header('Location: login.php'));
}*/
include("functions.php");
include("cnnxn.php");
connect();

if (isset($_GET['tid'])) {
	$SQLff='SELECT * FROM av_eventplayers WHERE id='.$_GET['tid'].';';
	$sendff=mysqli_query($db,$SQLff) or die(mysqli_error($db));
	$RSff=mysqli_fetch_object($sendff);
	$currentlistorder=$RSff->finishposition;
	
	
	$SQLdt='DELETE FROM av_eventplayers WHERE id='.$_GET['tid'].';';
	$senddt=mysqli_query($db,$SQLdt) or die(mysqli_error($db));
	
	
	
	$SQLfl='SELECT * FROM av_eventplayers WHERE eventid='.$_GET['eid'].' AND divisionid='.$_GET['did'].' ORDER BY finishposition ASC;';
	$sendfl=mysqli_query($db,$SQLfl) or die(mysqli_error($db));
	$listlength=mysqli_num_rows($sendfl);
	mysqli_data_seek($sendfl,0);
	
	if ($currentlistorder<=$listlength) {
		while ($RSfl=mysqli_fetch_object($sendfl)) {
			if ($currentlistorder<$RSfl->finishposition) {
				$newposition=$RSfl->finishposition-1;
				$SQLur='UPDATE av_eventplayers SET finishposition='.$newposition.' WHERE id='.$RSfl->id.';';
				$sendur=mysqli_fetch_object($SQLur);
			}
		}
	}	
	
	mysqli_close($db);
	die(header("Location: av_eventresults.php?eid=".$_GET['eid']));	
}

?>
